package br.atribuicoes.professor.producaoAcademica

import br.academia.Professor;

class ArtigoController {

	def scaffold = Artigo

	def save = {
		def artigoInstance = new Artigo(params)

		Professor professor = Professor.findByUsername(session.user)
		log.debug("PROFESSOR " + professor)
		if (professor){

			if (artigoInstance.save(flush: true)) {

				ProducaoAcademica producaoAcademica = new ProducaoAcademica()
				producaoAcademica.artigo = artigoInstance
				producaoAcademica.dataCadastro = new Date()

				//producaoAcademica.status = Status.ANALISE

				//	producaoAcademica.save(flush: true)
				professor.addToProducoesAcademica(producaoAcademica)
				redirect(action: "show", id: artigoInstance.id)
				flash.message = "${message(code: 'default.created.message', args: [message(code: 'Artigo.label', default: 'Artigo'), artigoInstance.id])}"
			}else{
				flash.error = "ERRO"
				redirect(action: "show", id: artigoInstance.id)
			}
		}
		else {
			flash.message("Professor Invalido no Sistema!")
			render(view: "create", model: [eventosInstance: artigoInstance])
		}
	}
}
